C++ = g++ -g -std=c++0x

ifndef os
  os = LINUX
endif

ifndef arch
  arch = IA32
endif

CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing #-msse3

ifeq ($(arch), IA32)
  CCFLAGS += -DIA32
endif

ifeq ($(arch), POWERPC)
  CCFLAGS += -mcpu=powerpc
endif

ifeq ($(arch), SPARC)
  CCFLAGS += -DSPARC
endif

ifeq ($(arch), IA64)
  CCFLAGS += -DIA64
endif

ifeq ($(arch), AMD64)
  CCFLAGS += -DAMD64
endif

OBJS = ../pcc/pcc_monitor_interval_queue.o ../pcc/pcc_utility_manager.o ../pcc/pcc_sender.o ../pcc/pcc_vivace_sender.o md5.o common.o window.o list.o buffer.o packet.o channel.o queue.o ccc.o cache.o core.o epoll.o api.o
DIR = $(shell pwd)

all: libudt.so libudt.a udt

%.o: %.cpp %.h udt.h
	$(C++) $(CCFLAGS) $< -c

libudt.so: $(OBJS)
ifneq ($(os), OSX)
	$(C++) -shared -o $@ $^
else
	$(C++) -dynamiclib -o libudt.dylib -lstdc++ -lpthread -lm $^
endif

libudt.a: $(OBJS)
	ar -rcs $@ $^

udt:
	cp udt.h udt

clean:
	rm -f *.o *.so *.dylib *.a udt

install:
	export LD_LIBRARY_PATH=$(DIR):$$LD_LIBRARY_PATH
